<?php
require_once "./db_config.php";
if($_POST['tempId']=='000'){
    $name=$_POST['name'];
    $id=$_POST['id'];
    $dept=$_POST['dept'];
    $from=$_POST['from'];
    $level=$_POST['level'];
    $duties=$_POST['duties'];
    $start_date=$_POST['start_date'];
    $end_date=$_POST['end_date'];

    $sql="SELECT MAX(tempId) FROM turnlist";
    $result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_assoc($result);
    $tempId=$row['MAX(tempId)']+1;

    $sql="INSERT INTO turnlist(`name`,`id`,`dept`,`from`,`level`,`duties`,`start_date`,`end_date`,`state`,`evaluate`,`tempId`)
    value ('$name','$id','$dept','$from','$level','$duties','$start_date','$end_date',0,0,'$tempId')";
    $result=mysqli_query($conn,$sql);
    if(!$result){
        die('error: ' . mysqli_error($conn));
    }else{
        echo "success";
    }
}
mysqli_close($conn);

//$data=$_POST['data'];
//for($key=0;$key<$data.length;$key++){
//    $name=$data[$key].name;
//    $id=$data[$key].id;
//    $dept=$data[$key].dept;
//    $from=$data[$key].from;
//    $level=$data[$key].level;
//    $duties=$data[$key].duties;
//    $start_date=$data[$key].start_date;
//    $end_date=$data[$key].end_date;
//    $tempId='';
//    echo $dept;
//}
